﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Exercitation.BLL;
using Yipusoft.Exercitation.Model;

public partial class Combat_TaskList : System.Web.UI.Page
{
    string departmentID;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtStartDate.Text = DateTime.Now.AddMonths(-6).ToString("yyy-MM-dd");
            txtEndDate.Text = DateTime.Now.AddDays(1).ToString("yyy-MM-dd");
            ListPageContral1.SetFirstPage();
            BindTask(0);
        }            
    }
    private void BindTask(int currPage)
    {
        departmentID = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        int count = TaskBase.GetCount("CreateDepartmentID='" + departmentID + "'");
        ListPageContral1.ItemCount = count;
        TaskList.DataSource = TaskBase.GetList(" CreateDate", " Desc", "CreateDepartmentID='" + departmentID + "' And CreateDate BETWEEN '"+txtStartDate.Text+"' And '"+txtEndDate.Text+"' ", ListPageContral1.PageSize, currPage);
        TaskList.DataBind();
    }
    public void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        BindTask(PageIndex);
    }
    protected void lnbtn_Command(object sender, CommandEventArgs e)
    {
        TaskBaseInfo taskinfo = TaskBase.GetTaskBase(new Guid(e.CommandArgument.ToString()));
        if (taskinfo.EndDate < DateTime.Now)
        {
            lblPrompt.Text = "结束日期小于当前日期";
            return;
        }
        taskinfo.SetOnDate = DateTime.Now;
        taskinfo.IsOn = true;
        TaskBase.Update(taskinfo);
        ListPageContral1.SetFirstPage();
        BindTask(0);
    }
    protected void TaskList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = ((ListPageContral1.CurrentPageIndex * ListPageContral1.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    public string GetDepartmentName(object objID)
    {
        if (objID == null)
            return "";
        return Yipusoft.Account.BLL.Department.GetDepartment(objID.ToString()).FullName;
    }

    protected void btnModify_Command(object sender, CommandEventArgs e)
    {
        TaskBaseInfo info = TaskBase.GetTaskBase(new Guid(e.CommandArgument.ToString()));        

    }
    protected void lnbtnQuery_Click(object sender, EventArgs e)
    {
        ListPageContral1.SetFirstPage();
        BindTask(0);
    }
}
